package com.huike.service.Statistics.course.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.dto.CoursePagDTO;
import com.huike.mapper.course.CourseMapper;
import com.huike.result.PageResult;
import com.huike.service.Statistics.course.CourseService;
import com.huike.vo.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
        //分页查询
    @Override
    public PageResult selectCourseList(CoursePagDTO dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        Page<Course>page = courseMapper.selectList(dto);
        return new PageResult(page.getTotal(),page.getResult(),200,"查询成功","");
    }
    //批量删除和删除
    @Override
    public void delete(List<Integer> ids) {
        courseMapper.delete(ids);
    }
    //课程新增
    @Override
    public void save(Course course) {
        course.setCreateTime(LocalDateTime.now());
        courseMapper.save(course);
    }
    //根据id查询
    @Override
    public Course SelectCourseById(Long id) {
        return courseMapper.SelectCourseById(id);
    }
    //课程修改
    @Override
    public void Upddate(Course course) {
        courseMapper.update(course);
    }

    @Override
    public List<Course> SelectCourseList() {
        return courseMapper.SelectCourseList();
    }
}
